<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>钟表练习</title>
    <style>
        /* 动画 */
        @keyframes spin{
            0%{
                transform: rotate(0);
            }
            100%{
                transform: rotate(360deg);
            }
        }
        .spin{
            animation-name: spin;
            animation-timing-function: linear;
            animation-iteration-count: infinite;
        }
        
        #panel{
            width: 600px;height: 600px;
            border: 1px solid;
            margin: 0 auto;
            background-image: url(clock.jpg);
            /* background-size: 100% 100%; 背景图大小和元素一样大 */
            background-position: 50% 50%; 
            position: relative;
        }
        .point{
            position: absolute;
        }
        /* 秒针 */
        #second-point{
            width: 4px;
            height: 250px;
            background-color: red;
            left: 298px;
            top: 100px;
            animation-duration: 60s;
            transform-origin: 50% 80%;
            border-top-left-radius: 50%;
            border-top-right-radius: 50%;
            
        }
        /* 分针 */
        #minute-point{
            width: 6px;
            height: 220px;
            background-color: royalblue;
            border-top-right-radius: 4px;
            border-top-left-radius: 4px;
            left: 297px;
            top: 120px;
            animation-duration: 60*60s;
            transform-origin: 50% 81%;
        }
        /* 时针 */
        #hour-point{
            width: 8px;
            height: 190px;
            background-color: plum;
            left: 296px;
            top: 150px;
            animation-duration: 12*60*60s;
            transform-origin: 50% 79%;
            border-top-left-radius: 50%;
            border-top-right-radius: 50%;
        }
        #dot{
            width: 10px;height: 10px;
            border-radius: 50%;
            background-color: black;
            border: 4px solid burlywood;
            top: 291px;
            left: 291px;
        }
    </style>
</head>
<body>
    <div id="panel">
        <div id="second-point" class="spin point"></div>
        <div id="minute-point" class="spin point"></div>
        <div id="hour-point" class="spin point"></div>

        <div id="dot" class="point"></div>
    </div>

    <script>
        var now = new Date();
        var h = now.getHours();
        var m = now.getMinutes();
        var s = now.getSeconds();
        var delay = h*60*60 + m*60 + s;
        var sp = document.getElementById("second-point");
        var mp = document.getElementById("minute-point");
        var hp = document.getElementById("hour-point");

        sp.style.animationDelay = -delay + "s";
        mp.style.animationDelay = -delay + "m";
        hp.style.animationDelay = -delay + "h";
    </script>
</body>
</html>